import 'package:flutter/material.dart';
import 'package:flutter_food_ordering_web/res/colors.dart';
import 'package:flutter_food_ordering_web/res/dimens.dart';
import 'package:flutter_food_ordering_web/res/styles.dart';
import 'package:flutter_food_ordering_web/routers/fluro_navigator.dart';
import 'package:flutter_food_ordering_web/routers/routers.dart';
import 'package:flutter_food_ordering_web/widget/load_image.dart';

class NavigationBar extends StatefulWidget {

  final int count;

  NavigationBar({Key key, @required this.count}) : super(key: key);

  @override
  _NavigationBarState createState() => _NavigationBarState();
}

class _NavigationBarState extends State<NavigationBar> {

  TextEditingController _searchController = TextEditingController();
  // final FocusNode _nodeText = FocusNode();

  @override
  void dispose() {
    //销毁TextField监听
    _searchController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.bottomCenter,
      height: 70,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Row(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              SizedBox(width: 120,),
              LoadAssetImage('logo',
                width: 109,
                height: 28,
              ),
            ],
          ),
          Row(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Container(
                width: 130,
                height: 31,
                child: TextField(
                  style: TextStyles.textDark14,
                  // focusNode: _nodeText,
                  obscureText: false,
                  // autofocus: true,
                  controller: _searchController,
                  textInputAction: TextInputAction.done,
                  keyboardType: TextInputType.text,
                  decoration: InputDecoration(
                    contentPadding: const EdgeInsets.all(2),
                    hintText: '搜索',
                    hintStyle: TextStyles.textGray14,
                    filled: true,
                    fillColor: Color(0xFFEFEFEF),
                    border: OutlineInputBorder(
                      borderRadius: BorderRadius.zero,
                      borderSide: BorderSide(
                            color: Color(0xFFA4D63A),
                            width: 0.5
                      )
                    ),
                    enabledBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.zero,
                      borderSide: BorderSide(
                            color: Color(0xFFA4D63A),
                            width: 0.5
                      )
                    ),
                    focusedBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.zero,
                      borderSide: BorderSide(
                            color: Color(0xFFA4D63A),
                            width: 0.5
                      )
                    ),
                  ),
                ),
              ),
              SizedBox(width: 14),
              Stack(
                children: <Widget>[
                  _buildCartButton(context),
                  Positioned(
                    right: 18,
                    child: LoadAssetImage('store/store_bubble',
                      width: 18,
                      height: 14,
                    ),
                  ),
                  Positioned(
                    right: 23,
                    child: Text('${widget.count}',
                      style: TextStyle(
                        fontSize: Dimens.font_sp10,
                        color: Colors.white
                      ),
                    )
                  )
                ],
              ),
              SizedBox(width: 120,)
            ],
          )
        ],
      ),
    );
  }

  Widget _buildCartButton(BuildContext context) {
    return InkWell(
      onTap: (){
        debugPrint('进入购物车');
        NavigatorUtils.push(context, Routes.checkout);
      },
      child: Container(
        width: 130,
        height: 31,
        decoration: BoxDecoration(
          color: Color(0xFFEFEFEF),
          border: Border.all(
            color: Color(0xFFA4D63A),
            width: 0.5
          )
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Row(
              children: <Widget>[
                SizedBox(width: 12),
                LoadAssetImage('store/logo_store',
                  width: 29,
                  height: 19,
                ),
                SizedBox(width: 5),
                Text('我的餐车',
                  style: TextStyle(fontSize: 11, color: Colours.text_dark),
                )
              ]
            ),
            Row(
              children: <Widget>[
                LoadAssetImage('store/store_right_arrow',
                  width: 6,
                  height: 6,
                ),
                SizedBox(width: 13)
              ],
            )
          ]
        ),
      ),
    );
  }
}